<template>
	<div class="hello">
		<el-container>
			<el-header>
				<h2>系统配置</h2>
			</el-header>
			<el-main>
				<el-form>
					<el-form-item label="网盘密码">
						<el-input v-model="net_oss.password" placeholder="网盘密码"></el-input>
					</el-form-item>
					<p>当前使用:{{now_user}}</p>
					<el-form-item>
						<el-button type="primary" @click="biu">踢掉</el-button>
					</el-form-item>
					<el-form-item>
						<router-link to="/">
							<el-button>返回</el-button>
						</router-link>
						<el-button type="primary" @click="onSubmit">设置</el-button>
					</el-form-item>
				</el-form>
			</el-main>
			<el-footer>
				<a>copyright@lilou(饮水机管理员)</a>
			</el-footer>
		</el-container>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				now_user: '无',
				net_oss: {
					password: 'default'
				}
			}
		},
		created() {
			this.get_net_oss();
			this.get_now_user();
		},
		methods: {
			onSubmit() {
				if (this.net_oss.password === "") {
					this.$message({
						type: 'error',
						message: '不可以为空～'
					})
				} else {
					axios.post('reset_net_oss', {
						data: this.net_oss
					}).then((res) => {
						if (res.data.data === 'error') {
							this.$message({
								type: 'error',
								message: "出现了未知错误～"
							});
						} else if (res.data.data === 'success') {
							this.$message({
								type: 'success',
								message: "修改成功啦～"
							});
							//刷新页面
							this.$router.go(0);
						}
					})
				}
			},
			biu() {
				axios.get('biu_now_user').then((res) => {
					if (res.data.data === 'nobody') {
						this.$message({
							type: 'error',
							message: "现在没人使用啦～"
						});
					} else if (res.data.data === 'success') {
						this.$message({
							type: 'success',
							message: "成功踢掉啦～"
						});
						this.$router.go(0);
					}
				})
			},
			get_net_oss() {
				axios.get('get_net_oss')
					.then((res) => {
						this.net_oss.password = res.data.data
					})
			},
			get_now_user() {
				axios.get('get_now_user')
					.then((res) => {
						if (res.data.data !== 'null') {
							this.now_user = res.data.data
						} else {
							this.now_user = '无'
						}
					})
			}
		}
	}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
	h1, h2 {
		font-weight: normal;
	}

	ul {
		list-style-type: none;
		padding: 0;
	}

	li {
		display: inline-block;
		margin: 0 10px;
	}

	a {
		color: #42b983;
	}

	a:link {
		font-size: 12px;
		color: #000000;
		text-decoration: none;
	}

	a:visited {
		font-size: 12px;
		color: #000000;
		text-decoration: none;
	}

	a:hover {
		font-size: 12px;
		color: #999999;
		text-decoration: underline;
	}
</style>
